package com.jwdf.uda.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.jwdf.uda.R;
import com.jwdf.uda.event.UserEvent;
import com.jwdf.uda.ui.fragment.base.BaseFragment;
import com.jwdf.uda.ui.fragment.user.register.BindMobileFragment;
import com.jwdf.uda.ui.fragment.user.register.MobileVerifyFragment;
import com.jwdf.uda.ui.fragment.user.register.SecureAccountFragment;
import com.jwdf.uda.ui.fragment.user.register.UpdateInfoFragment;
import com.jwdf.uda.utils.EventBusUtil;

/**
 * Created by Administrator on 2016/5/24.
 */
public class RegisterActivity extends AbsTitleBarActivity {

    public static void start(Context context) {
        context.startActivity(new Intent(context, RegisterActivity.class));
    }

    @Override
    protected String getTopTitle() {
        return getString(R.string.register);
    }

    @Override
    protected BaseFragment onCreateContentFragment() {
        return new BindMobileFragment();
    }

    @Override
    protected void onStart() {
        super.onStart();
        EventBusUtil.registerEvent(this);
    }

    @Override
    protected void onStop() {
        super.onStop();
        EventBusUtil.unregisterEvent(this);
    }

    public void onEvent(UserEvent event) {
        switch (event.getEvent()) {
            case UserEvent.EVENT_STEP_1:
                Bundle step1_args = new Bundle();
                step1_args.putString("mobile", event.getExtra());
                switchFragment(new MobileVerifyFragment(), step1_args);
                break;
            case UserEvent.EVENT_STEP_2:
                String extras[] = event.getExtra().split("##");
                Bundle step2_args = new Bundle();
                step2_args.putString("mobile", extras[0]);
                step2_args.putString("auth_code", extras[1]);
                switchFragment(new SecureAccountFragment(), step2_args);
                break;
            case UserEvent.EVENT_STEP_3:
                Bundle step3_args = new Bundle();
                step3_args.putString("avatar_url", event.getExtra());
                switchFragment(new UpdateInfoFragment(),step3_args);
                break;
            case UserEvent.EVENT_STEP_4:
//                if (ConfigUtils.isStylist(RegisterActivity.this)) {
//                    startNewActivity(StylistActivity.class);
//                } else {
                    startNewActivity(DefaultMainActivity.class);
//                }
                finish();
                break;
        }
    }
}
